package interview.streamTest;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.val;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: zhangrongqing
 * @Date: 2019/11/27 16:13
 */
public class StreamTestCase {
    public static void main(String[] args) {
        List<StudentCourseScore> studentCourseScores = Arrays.asList(
                new StudentCourseScore("zrq", "male", "math", 10),
                new StudentCourseScore("zrq", "female", "math", 15),
                new StudentCourseScore("zzz", "male", "math", 20),
                new StudentCourseScore("zzz", "male", "chinese", 30),
                new StudentCourseScore("mm", "male", "math", 50),
                new StudentCourseScore("hh", "male", "math", 45)
        );

        Map<String, List<StudentCourseScore>> result = studentCourseScores.stream().collect(Collectors.groupingBy(StudentCourseScore::getName));
        for (String key : result.keySet()) {
            System.out.println("key:" + key + ",value" + result.get(key));
        }

        Map<Student, List<StudentCourseScore>> resultByStudent = studentCourseScores.stream().collect(Collectors.groupingBy(item -> new Student(item.getName(), item.getSex())));
        for (Student key : resultByStudent.keySet()) {
            System.out.println("key:" + key + ",value" + resultByStudent.get(key));
        }

    }
}

@Data
@AllArgsConstructor
class StudentCourseScore {

    private String name;
    private String sex;
    private String course;
    private Integer score;

}

@Data
@AllArgsConstructor
class Student {
    private String name;
    private String sex;
}